﻿using EFModel;
using IServices;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using xm.Controllers;

namespace Serives
{
    [Obsolete]
    public class Teconfig_major_kind: Iconfig_major_kind
    {
        private readonly MyDBContext he;

        public Teconfig_major_kind(MyDBContext he)
        {
            this.he = he;
        }

        Task<ResultInfo> Iconfig_major_kind.Index7(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.config_major_kind;
                var list = he.config_major_kind
                    .Select(e => new { e.major_kind_id, e.major_kind_name, e.mfk_id })
                    .OrderBy(q => q.mfk_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }

        Task<int> Iconfig_major_kind.Inser4(string major_kind_id, string major_kind_name)
        {
            return Task.Run(() => {
                string sql = $@"insert into [dbo].[config_major_kind]([major_kind_id],[major_kind_name])
                            values('{major_kind_id}','{major_kind_name}');";

                int i = he.Database.ExecuteSqlCommand(sql);
                return i;
            });
        }

        Task<string> Iconfig_major_kind.Cz()
        {
            return Task.Run(() => {
                var list = he.config_major_kind.Max(e => e.major_kind_id).ToList();
                return JsonConvert.SerializeObject(list);
            });
        }

        Task<int> Iconfig_major_kind.delt4(int mfk_id)
        {
            return Task.Run(() => {
                string sql = $@"delete from [dbo].[config_major_kind]
                            where [mfk_id]={mfk_id}";

                int i = he.Database.ExecuteSqlCommand(sql);
                return i;
            });
        }
    }
}
